class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution:
    def isSymmetric(self, root: TreeNode) -> bool:
        if root is None:
            return True
        return self.dfs(root.left, root.right)

    def dfs(self, A:TreeNode, B:TreeNode):
        if A is None and B is None:
            return True
        if A is None or B is None:
            return False
        
        if A.val != B.val:
            return False
        return self.dfs(A.left, B.right) and self.dfs(A.right, B.left)